package com.csw.mysqldate.Transaction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("TransactionAuto")
public class PersonTransationAutoCommit {
    @Autowired
    private TransactionTemplate template;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping("show")
    public void show(String name) {
        System.out.println("Thread.currentThread().getName() = " + Thread.currentThread().getName());
        System.out.println("======>show...");

        template.execute(status-> {
            System.out.println(">>>>>>数据库操作");

            template.execute(status1 -> {
                String date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date());
                jdbcTemplate.execute("insert into people(create_time,end_time) values ('" + date + "','" + date + "')");

                System.out.println(">>>>>>数据库操作");
                return null;
            });

            int i=1/0;
            return null;
        });

    }
//————————————————
//    版权声明：本文为CSDN博主「魔道不误砍柴功」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
//    原文链接：https://blog.csdn.net/qq_35971258/article/details/128620476
}
